package com.hsmw.api.controller.pub;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hsmw.api.service.*;
import com.htn.common.core.constant.ChildOrderStatusEnum;
import com.htn.common.core.utils.StringUtils;
import com.hsmw.domain.HsmwOrderVehicleRelation;

import java.util.ArrayList;
import java.util.List;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap;
public class CheckPushTask extends TimerTask {

    HsmwOrderVehicleRelationService hsmwOrderVehicleRelationService;
    WebSocket  webSocket;
    RedisCache redisCache;
    public CheckPushTask(  HsmwOrderVehicleRelationService hsmwOrderVehicleRelationService,WebSocket  webSocket, RedisCache redisCache) {

        this.hsmwOrderVehicleRelationService= hsmwOrderVehicleRelationService;
        this.webSocket=webSocket;
        this.redisCache= redisCache;
    }

    @Override
    public void run() {
        ConcurrentHashMap<String,WebSocket> webSocketSet =    webSocket.webSocketSet;
        System.out.println("websocket 池的集合的size webSocketSet.size()="+ webSocketSet.size());
        //查询出所有的已经出发的订单 但是还未完成的订单
        List statusList = new ArrayList();
        statusList.add(ChildOrderStatusEnum.STARTUP.getValue());
        statusList.add(ChildOrderStatusEnum.ARRIVED.getValue());
        statusList.add(ChildOrderStatusEnum.WORKING.getValue());
        statusList.add(ChildOrderStatusEnum.UNDERREVIEW.getValue());
        List<HsmwOrderVehicleRelation> relationList= hsmwOrderVehicleRelationService.list(new LambdaQueryWrapper<HsmwOrderVehicleRelation>()
                .in(HsmwOrderVehicleRelation::getOrderStatus,statusList));
        relationList.stream().forEach(hsmwOrderVehicleRelation -> {
            // 如果 司机在线 同时
            if(null!=webSocketSet.get(hsmwOrderVehicleRelation.getDriverUsername())){


            }
        });

    }
}
